﻿using Abp.Domain.Entities;
using IntelligentAgriculture.Contracts.Interface.EarTagService;
using IntelligentAgriculture.Contracts.Interface.IManagements;
using IntelligentAgriculture.Contracts.Interface.Iridgepletype;
using IntelligentAgriculture.Domain.Entity;
using IntelligentAgriculture.WebAPI.Application.Command.ManageCommand;
using IntelligentAgriculture.WebAPI.Application.Command.RidgepCpoamd;
using MediatR;

namespace IntelligentAgriculture.WebAPI.Application.CommandHandler.RidgepCommandHandler
{
    public class RidgepAddCommandHandler : IRequestHandler<RidgepAddCommand, Results<int>>
    {
        private readonly IridegpoleService _iridegpoleService;

        public RidgepAddCommandHandler(IridegpoleService iridegpoleService)
        {
            _iridegpoleService = iridegpoleService;
        }
        /// <summary>
        /// 添加新的栋舍功能
        /// </summary>
        /// <param name="request">包含栋舍添加所需的请求信息</param>
        /// <param name="cancellationToken">用于取消操作的令牌</param>
        /// <returns>返回一个表示栋舍添加操作结果的任务</returns>
        public async Task<Results<int>> Handle(RidgepAddCommand request, CancellationToken cancellationToken)
        {
            try
            {
                var Rideg = new Ridgepole()
                {
                    SheepId = request.SheepId,
                    State = request.State,
                    CreateName = request.CreateName,
                    CreateTime = request.CreateTime,
                    ProductionPersonnel = request.ProductionPersonnel,
                    Remark = request.Remark,
                    ResponsiblePerson = request.ResponsiblePerson,
                    RidgepoleId = request.RidgepoleId,
                    RidgepoleName = request.RidgepoleName,
                    RidgepoleTypeId = request.RidgepoleTypeId,
                    UpdateName = request.UpdateName,
                    IsDel = false,
                };


                var result = await _iridegpoleService.Add(Rideg);
                return Results<int>.DataResult(result);
            }
            catch (Exception)
            {

                throw;
            }
        }
    }
}
